<?php
import("ORG.Util.Function");
import("@.ORG.Utils");


class TagAction extends CommonAction{	
	
	public function _initialize(){
		parent::_initialize();				
		$param           =    $this->_get('_URL_');
		$controller      =    $param[0];
		$action          =    $param[1];		
		//language
		$lang            =    L($action);  		
		$manage          =    L('manage');
		
		$this->assign("manage",$manage);
		$this->assign("current",$lang);
		$this->assign("lang",$lang);
	}
	
	public function _empty(){
		t('空操作');
	}
	
	// 标签列表
	public function tag_list(){
		$TagModel	=	new TagModel();	
		$tagList	=	$TagModel->getTagList();
		$this->assign("tagList",$tagList);
		$this->display();
	}
	
	// 添加标签
	public function add_tag(){
		$this->display();
	}

	// 处理添加标签
	public function add_tag_ok(){
			
	    $tag_words 	= 	empty($_POST['tag_name']) ? '' : trim($_POST['tag_name']);
	    $id 		= 	intval($_POST['id']);
	    $goods_id 	= 	intval($_POST['goods_id']);
	    if ($goods_id <= 0){
	        $this->error("商品不存在");
	    }
		
	    $tag['goods_id'] 		=	$_POST['goods_id'];
	    $tag['tag_words'] 		=	$_POST['tag_name'];
	    $tag['user_id'] 		=	$_SESSION['user_id'] ? $_SESSION['user_id'] : 0;
	    
	    if( M('Tag')->add($tag) ){
	    	$this->success('操作成功',U('tag/tag_list'));
	    }
	    else{
	    	$this->error('操作失败',U('tag/tag_list'));
	    }
	}
	
	// 修改标签
	public function mod_tag(){
		
	}
	
	// 删除标签
	public function del_tag(){		
		$id			= 	intval($_GET['id']);		
		$result		=	M('Tag')->where(" tag_id='{$id}' ")->delete();
		if($result){
			$this->success("操作成功",U('tag/tag_list'));
		}
		else{
			$this->success("操作失败",U('tag/tag_list'));
		}
	}
	
	
	
	
}
?>